package com.sduept.nwld.dataserver.manager.config;

import com.sduept.bigdata.fault.entity.DataFilterConfig;
import com.sduept.core.dao.SuperDAO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DataFilterConfigManager {
	@Autowired
	private SuperDAO dao;

	public DataFilterConfig save(DataFilterConfig config) {
		return dao.createOrUpdate(config, DataFilterConfig.class);
	}

	public void deleteConfigById(String id) {
		dao.delete(id, DataFilterConfig.class);
	}

	public DataFilterConfig getConfigById(String id) {
		return dao.findById(id, DataFilterConfig.class);
	}

	public List<DataFilterConfig> listRootConfigs() {
		return dao.findByCondition(" pid is null", DataFilterConfig.class);
	}

	public List<DataFilterConfig> listConfigsByPid(String pid) {
		return dao.findByPid(pid, DataFilterConfig.class);
	}

	public List<DataFilterConfig> listAllConfigs() {
		return dao.findAll(DataFilterConfig.class, " order by id");
	}

	public void deleteByPid(String pid) {
		dao.deleteAllByPid(pid, DataFilterConfig.class);
	}

	public List<DataFilterConfig> findByName(String name) {
		List<DataFilterConfig> list = new ArrayList<DataFilterConfig>();
		if (StringUtils.isNotEmpty(name)) {
			list = dao.findByCondition(DataFilterConfig.class, "name like ?", "%" + name + "%");
		}
		return list;
	}
}
